<?php
	error_reporting(E_ALL || ~E_NOTICE);
	$i=1;  
	$sqlstr='';
	$accesstab='';
	$dbResult=array();

    $myconn=@mysql_connect("localhost","root","root");
    if(!$myconn)
    {
       die('Could not connect: '.mysql_error());
    }
    $db_selected=mysql_select_db("dwaccessDB",$myconn);
	if($db_selected)
    {
        $strSql="select distinct controlerNum from gatesetting ORDER BY lasttime DESC;";
		$result=mysql_query($strSql,$myconn);	        
        while($dbResult = mysql_fetch_array($result))
	    {	        		   
		    if($i==1)
	        {			        
	    		$accesstab = "{\"s".$i.'_'."0\":\"".$dbResult[0].'"';						
		    }else
			{
			    $accesstab = $accesstab.",\"s".$i.'_'."0\":\"".$dbResult[0].'"';
			}
            $i++;
//                @file_put_contents("test.log", "\n i =".$i." accesstab =".$dbResult[$i-1]."\n", FILE_APPEND);				
	    }
		$accesstab = $accesstab.",\"nrows\":\"".($i-1)."\"}";
	    mysql_free_result($result);
//			mysql_close($myconn);	
	    echo $accesstab;
//	    @file_put_contents("test.log", "\n accesstab =".$accesstab."\n", FILE_APPEND);
    }else
	{
	    die("Can't use database dwaccessDB : ".mysql_error());
        $string = "Can't use database : ".mysql_error();
        file_put_contents("test.log", $string, FILE_APPEND);
	}		
	mysql_close($myconn);    
?>